package galaxy.drawer.action;

import galaxy.drawer.Context;

import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;

public class ActionStack implements Iterable<Action>, Action {
	private Deque<Action> actions = new LinkedList<Action>();
	
	public ActionStack()
	{}

	public ActionStack addFirst(Action a)
	{
		actions.addFirst(a);
		return this;
	} 
	
	public ActionStack addLast(Action a)
	{
		actions.addLast(a);
		return this;
	}
	
	public Iterator<Action> iterator()
	{
		return actions.iterator();
	}
	
	public Context execute(Context c)
	{
		for (Action a : actions) {
			c = a.execute(c);
		}
		return c;
	}
}
